package datastructure.tree;

/**
 * @author XY
 * @version 1.0
 * @date 2022/1/14 9:21
 * @Description未完成
 */
public class Leet111 {
    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    class Solution {
        public int minDepth(TreeNode root) {
            if(root==null){
                return 0;
            }
            if(root.left==null&&root.right==null){
                return 1;
            }
            int min = Integer.MAX_VALUE;
            if(root.left!=null){
                min = Math.min(minDepth(root.left),min);
            }
            if(root.right!=null){
                min = Math.min(minDepth(root.right),min);
            }
            return min + 1;
        }
    }
}
